package com.small.xx.ai.apidoc.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * Swagger配置类
 */
@Configuration
@Import(ApiDocProperties.class)
@ConditionalOnProperty(name = "app.api-doc.swagger.enabled", havingValue = "true", matchIfMissing = true)
public class SwaggerConfig {

    @Bean
    public OpenAPI openAPI(ApiDocProperties apiDocProperties) {
        ApiDocProperties.Swagger swagger = apiDocProperties.getSwagger();
        return new OpenAPI()
                .info(new Info()
                        .title(swagger.getTitle())
                        .version(swagger.getVersion())
                        .description(swagger.getDescription())
                        .license(new License()
                                .name(swagger.getLicense())
                                .url(swagger.getLicenseUrl())
                        )
                );
    }
}